#or rather playing 4 d chess with an algorithm
Explore tagged Tumblr posts
saltyfilmmajor · 1 year ago
Text
Im high on nyquill but follow me here
Ethan is like the entity in that he can change whoever he is to undermine the government snd exploit its weaknesses
Lane is like the entity in that he is often described as omnipresent, someone who the characters state is a master manipulator, to get the outcome he wants
9 notes · View notes
adamblrworld-blog · 6 years ago
Text
Artificial Intelligence (AI)
Tumblr media
1) What is Artificial Intelligence?
Artificial Intelligence(AI) is a form of Computer Science used to create intelligent machines that can recognize human speech,objects,can learn,plan and solve problems like humans
It has become an essential part of the technology industry.Research associated with artificial intelligence is highly technical and specialized.Machines can often act and react like humans only if they have abundant information relating to the world. Artificial intelligence must have access to objects, categories, properties and relations between all of them to implement knowledge engineering.
Tumblr media
2) What is AI used for today?
It may come as a surprise that artificial intelligence is all around us - and has even permeated our routine on a daily basis. Whether on our phones or at the cutting edge of technological development, artificial intelligence is all around.
Siri/Alexa
Whether or not you've thought about that voice in your phone as a product of AI or not, Apple's Siri and Amazon's Alexa both use AI to help you complete tasks or answer questions on your mobile devices.
Facebook Feed
Believe it or not, your Facebook feed is actually using AI to predict what content you want to see and push it higher
Tesla
Its founder being vocally suspicious of advanced AI technology, Tesla's electronic cars use a variety of AI - including self-driving capacities. Tesla also uses crowd-sourced data from its vehicles to improve their systems
Netflix
The media streaming site uses advanced predictive technology to suggest shows based on your viewing preferences or rating. And while the data currently seems to favor bigger, more popular films over smaller ones, it is becoming increasingly sophisticated.
Ride-sharing Apps Like Uber and Lyft
How do they determine the price of your ride? How do they minimize the wait time once you hail a car? How do these services optimally match you with other passengers to minimize detours? The answer to all these questions is Machine Learning(ML).
Commercial Flights Use an AI Autopilot
AI autopilots in commercial airlines is a  surprisingly early use of AI technology that dates as far back as 1914, depending on how loosely you define autopilot. The New York Times reports that the average flight of a Boeing plane involves only seven minutes of human-steered flight, which is typically reserved only for takeoff and landing
Tumblr media
3)What are the 4 types of AI?
I)Reactive machines
The most basic types of AI systems are purely reactive, and have the ability neither to form memories nor to use past experiences to inform current decisions. Deep Blue, IBM’s chess-playing supercomputer, which beat international grandmaster Garry Kasparov in the late 1990s, is the perfect example of this type of machine.
Deep Blue can identify the pieces on a chess board and know how each moves. It can make predictions about what moves might be next for it and its opponent. And it can choose the most optimal moves from among the possibilities.
II) Limited memory
This Type II class contains machines can look into the past. Self-driving cars do some of this already. For example, they observe other cars’ speed and direction. That can’t be done in a just one moment, but rather requires identifying specific objects and monitoring them over time.
We might stop here, and call this point the important divide between the machines we have and the machines we will build in the future. However, it is better to be more specific to discuss the types of representations machines need to form, and what they need to be about.
III)Theory of mind
Machines in the next, more advanced, class not only form representations about the world, but also about other agents or entities in the world. In psychology, this is called “theory of mind” – the understanding that people, creatures and objects in the world can have thoughts and emotions that affect their own behavior.
IV) Self-awareness
The final step of AI development is to build systems that can form representations about themselves. Ultimately, we AI researchers will have to not only understand consciousness, but build machines that have it.
This is, in a sense, an extension of the “theory of mind” possessed by Type III artificial intelligence. Consciousness is also called “self-awareness” for a reason. (“I want that item” is a very different statement from “I know I want that item.”) Conscious beings are aware of themselves, know about their internal states, and are able to predict feelings of others. We assume someone honking behind us in traffic is angry or impatient, because that’s how we feel when we honk at others. Without a theory of mind, we could not make those sorts of inferences.
4)What is the purpose of AI?
The intended purpose of AI is to making an intelligent machine that initially thinks as good as a human, but eventually much better, even to the degree of far superior. The overall research goal of artificial intelligence is to create technology that allows computers and machines to function in an intelligent manner. The general problem of simulating (or creating) intelligence has been broken down into sub-problems.
The goal of AI is to create robots that can be adaptive like humans and perform multiple tasks. The main purpose in my eyes would be to save humans work
5)What are the advantages of artificial intelligence?
AI would have a low error rate compared to humans, if coded properly. They would have incredible precision, accuracy, and speed. They won't be affected by hostile environments, thus able to complete dangerous tasks, explore in space, and endure problems that would injure or kill us.
The greatest advantage of artificial intelligence is that machines do not require sleep or breaks, and are able to function without stopping. They can continuously perform the same task without getting bored or tired. When employed to carry out dangerous tasks, the risk to human health and safety is reduced
There are some benefits of artificial intelligence a. No mistake
 We use artificial intelligence in most of the cases. As this helps us in reducing the risk. Also, increases the chance of reaching accuracy with the greater degree of precision.
b. Easy Exploration
 In mining, we use artificial intelligence and science of robotics. Also, other fuel exploration processes. Moreover, we use complex machines for exploring the ocean. Hence, overcoming the ocean limitation.
c. Everyday Application
As we know that computed methods and learning have become commonplace in daily life. Financial institutions and banking institutions are widely using AI. That is to organize and manage data. Also, AI is used in the detection of fraud users in a smart card based system.
d. Digital Assistants
“Avatars” are used by highly advanced organizations. That are digital assistants. Also, they can interact with the users. Hence. They are saving human needs of resources.
As we can say that the emotions are associated with mood. That they can cloud judgment and affect human efficiency. Moreover, completely ruled out for machine intelligence.
e. No breaks
Machines do not require frequent breaks and refreshments for humans. As machines are programmed for long hours. Also, they can continuously perform without getting bored.
f. Increase Work Efficiency
For a particular repetitive task, AI-powered machines are great with amazing efficiency. Best is they remove human errors from their tasks to achieve accurate results.
g. Reduce cost of training and operation
Deep Learning and neural networks algorithms used in AI to learn new things like humans do. Also, this way they eliminate the need to write new code every time.
6)What are the disadvantages of artificial intelligence?
a. High Cost
Its creation requires huge costs as they are very complex machines. Also, repair and maintenance require huge costs.
b. No Replicating Humans
As intelligence is believed to be a gift of nature. An ethical argument continues, whether human intelligence is to be replicated or not.
c. Lesser Jobs
As we are aware that machines do routine and repeatable tasks much better than humans. Moreover, machines are used of instead of humans. As to increase their profitability in businesses.
Tumblr media
d. Lack of Personal Connections
We can’t rely too much on these machines for educational oversights. That hurt learners more than help.
e. Addiction
As we rely on machines to make everyday tasks more efficient we use machines.
0 notes
targetdummy · 8 years ago
Text
I’m not interesting, but I was tagged by @givemebishies to answer some stuff about. These probably won’t be that cool or interesting for anyone else to read, but here we go!
Rules: Answer all questions, add one question of your own and tag as many people as there are questions.
1. Coke or Pepsi: Pepsi. It’s sweeter, and you’re supposed to sip soda rather than drinking it like water. Plus, MJ still forgave them after they caught his hair on fire, started his painkiller addiction, and dropped him as a promoter because of the child abuse allegations, so I imagine he at least liked to drink it.
2. Disney or Dreamworks: Disney generally. I’m not a big fan of either one, but I think Disney has made more important things in their time. Kind of unfair since they’ve been around longer, but whatever.
3. Coffee or Tea: Cappuccino. And even then I don’t want to taste the coffee in it.
4. Books or Movies: I watch more movies, but I think more books have had a serious impact on my life. I don’t know though, Rocky is a freaking masterpiece.
5. Windows or Mac: What? Where is my GNU/Linux option? Richard Stallman didn’t die for this! [For real though, I use Windows because I’m peasant trash who likes to play video games without spending hours on configuration. Though, I am considering dual-booting with Linux Mint in the near future. We’ll see. And Stallman isn’t dead, that was a joke.]
6. DC or Marvel: Marvel. Gotta have my Spider-Man and X-Men. The Avengers are also much more varied and interesting than the Justice League.
7. Xbox or Playstation: Playstation all the way. I can’t even name an Xbox exclusive offhand other than Halo or Gears of War. Playstation has a more interesting history too.
8. Dragon Age or Mass Effect: A friend of mine kept telling me to play both, but stressed Dragon Age more. I have played neither.
9. Night Owl or Early Rise: Night owl. I feel and work better at night. I like knowing the rest of the world is asleep.
10. Cards or Chess: Cards because they are an unlimited number of games! (So is Chess technically, but I like that with cards you can more easily have a random aspect if you want).
11. Chocolate or Vanilla: Are we talking ice cream? Vanilla. Are we talking brownies? Chocolate. Are we talking anything else? I don’t know.
12. Vans or Converse: I buy the cheapest shoe that feels comfortable and doesn’t make me hate myself when I wear them. I’ve never owned either of those.
13. Lavellan, Trevelyan, Cadash or Adaar: I’m sorry, I’m only a level 2 mage, I don’t know those ones yet.
14. Fluff or Angst: both I guess? I’m an angst lookin’ to get his fluff on.
15. Beach or Forest: Beach beach beach. I need to be warm and surrounded by water.
16. Dogs or Cats: I like cats and dogs that act like cats.
17. Clear Skies or Rain: Rain all the way. Rain for days. Clear skies are boring and make me sad. They don’t even move. I can feel rain. It surrounds me and makes me feel loved. Warm rain especially, or cool rain on a warm day.
18. Cooking or Eating Out:  I prefer eating out in both senses of the term. But for real, I love restaurants. I love the feeling of being in one, and knowing that my food is being handled by someone who knows how to make it well. Then to just have it brought to me, it’s awesome. Like, I didn’t make this. I don’t deserve this. But you’re giving me this, just for some paper. It’s just so comforting. Oh, and takeout is awesome too, because it’s that experience, but with more control and less atmosphere. All of it makes me so happy, honestly, I can’t understate how awesome it is to pickup food from somewhere awesome. Shout out to my people at El Canelo, that’s the place I dream of when I’m hungry. Any Chinese/Japanese is great too. Then fast food, Sheetz and Chick-Fil-A especially can be great. All of it, man. I’m sorry, I wrote too much for this.
19. Spicy Food or Mild Food: Spicy! Specifically, spicy and sweet. It’s all a part of the experience!
20. Halloween/Samhain or Solstice/Yule/Christmas: Halloween is cooler theme-wise. Japanese Christmas though 💕
21. Would you rather forever be a little too cold or a little too hot : Yeah, I guess a little too cold, because I love the sensation of getting warm.
22. If you could have a superpower, what would it be? Phew, does what Dr. Manhattan have count? You know, just be god. Nah, I wouldn’t want that, that’s too much. Controlling time would be cool. Would probably be depressing in reality, but cool in theory.
23. Animation or Live Action: This really depends on the work.
24. Paragon or Renegade: I have no idea what this is referencing. But Renegade is a 1986 beat ‘em up game that I really like for one reason: it’s the start of the Kunio-Kun series that would eventually lead to Downtown Nekketsu Monogatari, or River City Ransom. Renegade isn’t amazing on its own, but really cool to see where RCR got its origin.
25. Baths or Showers: Showers usually.
26. Team Cap or Team Iron Man: Haven’t watched Civil War yet, but Iron Man.
27. Fantasy or Sci-Fi: Sci-Fi usually feels bigger than Fantasy and can include Fantasy elements without much of an issue (infinite universe, infinite possibilities), so I’ll go with it.
28. Do you have three or four favourite quotes?
Okay, these might get lengthy, so here we go:
1. (Solid Snake from Metal Gear Solid 2)
“Life isn't just about passing on your genes. We can leave behind much more than just DNA. Through speech, music, literature and movies... what we've seen, heard, felt... anger, joy and sorrow... these are the things I will pass on. That's what I live for. We need to pass the torch, and let our children read our messy and sad history by its light. We have all the magic of the digital age to do that with. The human race will probably come to an end some time, and new species may rule over this planet. Earth may not be forever, but we still have the responsibility to leave what traces of life we can. Building the future and keeping the past alive are one and the same thing. “
2. (Dr. Manhattan from Watchmen)
“Nothing ends, Adrian. Nothing ever ends.”
3. (Shigeru Miyamoto)
“A delayed game is eventually good, but a rushed game is forever bad.“
And there’s a lot more but I’m bad at remembering them.
29. YouTube or Netflix: YouTube, I watch it way more than Netflix. I like all the different voices on YouTube, how accessible it is.
30. Harry Potter or Percy Jackson: Isn’t Harry Potter a My Immortal fanfic? I go with that one. Also, nobody will even remember Percy Jackson in ten years.
31. When You Feel Accomplished: When I’ve created something that people enjoy, and when I fulfill the needs of those I love. I haven’t been doing enough of either lately :/
32. Star Wars or Star Trek: I accept that Star Trek is superior in every way, however I will always defend Star Wars as my personal favorite.
33. Paperback Books or Hardback Books: Hardback. I am less likely to ruin it, and it looks nicer on a shelf.
34. horror or rom-com: I’m not a fan of either, but I like horror elements in other things.
35. tv shows or movies: TV shows. Individual stories that build to an overall story arc will always have more depth than a single movie. That’s why Samurai Jack is more compelling than any of the samurai movies it draws inspiration from.
36. favorite animal: Tiger.
37. favorite genre of music: Funk and its derivatives.
38. least favorite book: The Old Man and the Sea. I like Hemmingway, but it’s a book where nothing happens, the most exciting part is when he says the ocean is a women having her period, and the ending feels like actually watching an old man die. He doesn’t die in the book, that’s just how it feels.
39. favourite season: Summer. As hot as possible.
40. song that’s currently stuck in your head: ME NE’ER HA ME GUN SO ME HA TA MOO SHARP LI ME KNIFE
41. what kind of pyjama’s do you wear? Pajama pants and a t-shirt. I wear this all day when possible.
42. Handwriting or Typing? Typing. Gotta go fast. And I can’t compile my code from a piece of paper.
43. If you can only choose one song to be played at your funeral, what would it be? The Real Folk Blues.
44. What is your go to book/movie/tv show that you immediately find solace in when you feel down? Okay, I don’t know about books, movies, or TV shows, but I always find solace in any YouTube show that can make me feel less alone. It doesn’t have to be funny or interesting, I just have to feel like people are around me, talking, and being happy. Game Grumps works well for this, or most podcasts.
45. “Yer a wizard/witch, Y/N” - your reaction? I know. I didn’t learn to code just to not be a wizard.
46. Are you generally a messy or organized person? I’m an organized person who appears messy. It’s like a hashing algorithm. There is some initial data behind it, but you can’t make sense of the result, and there’s no way to reverse it.
47. What’s your go to comfort food? Anything fried. Especially fries. It just feels so familiar, so welcoming, like it can never be bad. Especially with good sauces, sweet and sour most of all probably.
48. Do you enjoy being creative? If so what’s your favorite way to create? I do. I’m not sure what my favorite way is. Writing is easiest, but making games and web stuff is so rewarding. I need to do more either way.
My question:
49: Other than Tumblr, what is your favorite website?
I have no friends to tag :D (But if you see this and nobody tagged you to do it, you can totally say I tagged you and do it anyway. I’ll vouch for you.)
3 notes · View notes
holytheoristtastemaker · 5 years ago
Quote
Tetris is simpler to play than it is to make. When I started making Tetris I learned that there are several tasks I needed to complete in isolation. Namely they were animation, collision detection and the row-clearing algorithm. This is what my version of the game looked like on my first try: First attempt at making Tetris.I also wanted to create a dynamic-size well. Meaning that the size of the playing area could be adjusted. The well and tetromino blocks can be represented by arrays. Keyboard events can be used to take user input. I made it easy to change colors by storing them in a global variable color. Using global variables is often shunned. But we’re just creating a simple Tetris demo here in vanilla JavaScript. Global colors can be stored as follows: let color = { background: "#5c2a3b", // background wall: "#d83c66", // walls solid: "#49b5ab", // solid tetromino tetromino: "#e97539" }; // falling tetromino To change the color theme, simply modify these colors. For this demo, all tetrominos will share the same color. But this can be adjusted later. I just don’t want to over-complicate the code so the key principles remain clear. Complete Tetris Source Code This tutorial is based on existing Tetris code I wrote a week ago. You can fork the Complete Tetris source code from my GutHub profile. *I won’t be listing entire source code in this tutorial to avoid redundancy. But all important functions will be listed here. Project Background No, this is not the best, most optimized Tetris game written in JavaScript. Nor is it the only way to program it in JavaScript. I used simple constructs (arrays and for-loops) to make it easier to see how it all fits together. Optimizations can be applied later. This is not a tutorial on how to write the most efficient Tetris game. Rather, on the principles behind it. Game animation on a relatively small grid consisting of colored squares can be achieved using dynamic DIV elements. We don’t even have to use canvas. But there is nothing stopping us from implementing it on canvas either. A large number of games is grid-based. You can branch out from this setup to make any simple game that takes place on a 2D grid: chess, candy crush or a farming simulator like Stardew Valley for example. Well 10 by 20 is the classic size of the Tetris well. But it can be any size. In this demo we also have walls that happen to be part of the well array. So even though the well is 10 squares in width, with the walls it’s actually 12: I’ll write the code in such way that lets you specify your own dimensions of the well, regardless of how thin or wide it is: 50 x 36For example you can create a Tetris version with a 50-square wide well that is 36 squares deep (Sometimes it’s just fun to experiment.) let width = 50; // well width let height = 36; // well height let square_size = 16; // square size in pixels Let’s create the well array: let well = new Array(height); // array holding the entire well This array will hold a list of arrays. (created in the following section.) Generating The Well Each square in the well will have its own code. The basic idea is that 0 is empty space. Everything else (1, 2, 3, etc) is considered solid (collidable.) To generate empty space (0), left and right walls (1) and the bottom (2) all we have to do is assign those values to the wall array in proper places: // Reset entire well to all 0's for (let y = 0; y < width; y++) well[y] = new Array( height ).fill(0); // Mark bottom for (let x = 0; x < width; x++) well[x][height - 1] = 2; // Mark walls for (let y = 0; y < height; y++) { well[0][y] = 1; well[width - 1][y] = 1; } The code to create an HTML element is shown below. It is then inserted into element. That’s why our starting HTML document is pretty much empty — all blocks are generated and inserted into DOM dynamically: // Generate well on the screen by creating HTML elements dynamically for (let y = 0; y < height; y++) { for (let x = 0; x < width; x++) { // Create a DIV element dynamically let square = document.createElement("div"); // Create an intuitive easy to access ID, eg: "square_x5y13" square.setAttribute("id", "square_x" + x + "y" + y); // Set some CSS properties for the square square.style.position = "absolute"; square.style.left = x * square_size + "px"; square.style.top = y * square_size + "px"; square.style.width = square_size + "px"; square.style.height = square_size + "px"; square.style.zIndex = 0; let block_type = well[x][y]; // Empty space color: if (block_type == 0) square.style.background = "#082b7f"; // Wall color: if (block_type == 1) square.style.background = "#841550"; // Bottom wall color: if (block_type == 2) square.style.background = "#c20c98"; // Add created square to the dynamically document.body.appendChild( square ); } } This function goes through the entire well, checking the value at well[x][y]and generating a DIV element for each square individually. It then assigns a color to that square based on the value stored in block_type variable, which simply points to the value at well[x][y] Tetrominos The 7 classic patterns consisting of 4 squares are called tetrominos. The classic set of seven tetrominos.Notice that the long stick is the only tetromino that doesn’t fit into a 3x3 box: The stick is an odd-ball case as it’s the only tetromino that requires a 4x4 grid.We can deal with this stick separately or we can place all tetrominos into a 4x4 array instead. There are multiple ways of dealing with this problem. For this tutorial I’ll simply use a shorter stick that fits into a 3x3 box though. Representing a tetromino using a JavaScript array: To actually represent one of the tetrominos you will specify its solid parts by using value of 1 instead of 0: One way of defining a tetromino using a 1-dimensional array.You can define all of the tetrominos this way, and then place them into one array representing an entire list containing them all. If you want to get creative you can even make up your own shapes: let A = [0,0,1, 0,0,1, 0,1,1]; let B = [1,0,0, 1,0,0, 1,1,0]; let C = [0,0,0, 0,1,0, 1,1,1]; let D = [0,0,0, 0,1,1, 1,1,0]; let E = [0,0,0, 1,1,0, 0,1,1]; let F = [1,1,0, 1,1,0, 0,0,0]; let G = [0,0,0, 1,1,1, 0,0,0]; I then place all tetrominos into another array: let tetrominos = [A,B,C,D,E,F,G]; This way we can generate a random tetromino using the Math.rand function. We’ll also need placeholders for “next” and “current” tetromino. They are called current and next respectively: let current = [0,0,0, 0,0,0, 0,0,0]; let next = [0,0,0, 0,0,0, 0,0,0]; Here is the function that generates a random tetromino: // Generate a random tetromino and return it as 3x3 array function make_random() { // 1.) Select random tetromino from tetrominos array by index let index = Math.floor((Math.random() * tetrominos.length)); // 2.) Copy it into current array (avoid reference assignment) return [...tetrominos[ index ]]; } Here I used … (rest / spread syntax) to create a copy of an array. If we simply assign that array to a variable it would create a reference to the original tetromino. We don’t want a reference. So instead we’ll make a separate copy in memory. When we return [...tetrominos[index]] we’re making a copy of one of the tetrominos from our tetrominos[] array created earlier. To generate a random tetromino and store it in either current or next variable: current = make_random(); next = make_random(); Once the tetromino is permanently stuck in the well after it has fallen we can swap current with next one. Keyboard Controls Here is the keyboard controls source code: // Keyboard input document.addEventListener("keydown", (e) => { let key_code = e.keyCode; // Erase the teetromino erase(); // Left if (key_code == 37) { if (will_collide(dir.LEFT)) { reset(); } else position.x -= 1 } // Right if (key_code == 39) { if (will_collide(dir.RIGHT)) { reset(); } else position.x += 1 } // Down if (key_code == 40) { if (will_collide(dir.DOWN)) { reset(); } else position.y += 1 } if (key_code == 38) { position.y -= 1 } // Rotate if (key_code == 90) { rotate_left() } if (key_code == 88) { rotate_right(); } // Draw the current tetromino draw(); }); Falling Animation The game loop consists of erase, fall and draw functions. This is what creates the illusion of a falling block. // Game-loop Animation setInterval(() => { // Erase the current tetromino block from the well erase(); // Progress the tetromino by 1 square down fall(); // Draw the tetromino at its new fallen position draw(); }, 15); It is common to use setInterval function in games. But it was never intended for updating the screen. In fact, it’s a bit choppy. The only reason you don’t notice that is because Tetris animation is relatively slow. If we were making a faster-paced game where smooth animation matters we’d use requestAnimationFrame instead — it will sync our animation to the monitor’s refresh rate. However, in this simple Tetris game it probably makes little sense to actually do that because the results will be near-identical. Another problem is that Edge versions below 17 and Internet Explorer do not reliably fire requestAnimationFrame before the paint cycle. Collision Detection There are two types of collisions in Tetris. With walls and with fallen bricks. Collision detection in Tetris is tricky. You have to determine if the brick will collide with a wall, the bottom of the well, or other tetrominos one animation step before it is physically moved to that location. Because you want the tetromino to be placed on top of other blocking areas— not into them. To demonstrate what I mean, I created this animation that shows you tetrominos falling through the bottom of the well. Or painting the walls on contact. That’s the situation you want to avoid: Avoid writing collision detection in “real time.” You need to figure out if the current block will collide at a future time IF it is moved in the direction it is moving on the next frame, not on the current frame. And if there is a future collision, prevent any further movement and “paste” the brick into the well as a solid block (the latter is not shown on this animation, it will be explained in one of the following sections.)Note: at this stage we’re trying to determine collision only with walls and the bottom of the well. There is no collision between fallen blocks at this point. We’ll handle that later by pasting the block into the well and marking it solid. (This will be explained in one of the following sections.) To deal with the issue we can write a function to determine what happens to the tetromino in the future — IF it were moved one block left, right or down. We can do that by intercepting keyboard events. When a key is pressed, the function tells us whether the tetromino moved to the new position will generate a collision with the walls or other blocks. If there is no collision at that future location we will move the block there. Otherwise we paste block into the well array, mark it as a solid block and generate our next tetromino. Let’s take a look at this isolated example: // Left arrow key is pressed if (key_code == 37) { // Will tetromino collide with walls or if it is moved left? if (will_collide( dir.LEFT )) reset(); else // Tetromino will not collide, move to that position position.x -= 1; } If the function will_collide returns true we reset the view. The reset()function will actually paste the tetromino into the well at current position. Below is a listing of both reset() andpaste() functions: reset() The reset function is more of a helper function. It calls paste(), clear_row(), make_random(), update_next() and erases the fog of darkness. function reset() { paste(); // paste current tetromino onto the well clear_row(); // clear rows if any current = [...next]; // swap current and next tetromino next = make_random(); // generate next tetromino update_next(); // Update "next" box // reset current position to top and middle of the well position.x = parseInt(width/2) - 1; position.y = -3; reset_fog(); // clear the fog of darkness } paste() // "paste" current block onto the well function paste() { let index = 0; // Prevent pasting blocks that fall outside of the well: if (position.x >= 0 && position.x = -3 && position.y = 0 && position.x = -3 && position.y 0) { // Clear the well, except last row (well's bottom) for (let y = 0; y < height - 1; y++) { // Clear all except walls ([0] and [width - 1]) for (let x = 1; x < width - 1; x++) { well[x][y] = 0; // Paint empty square let square = document.getElementById("square_x" + x + "y" + y); if (square) square.style.backgroundColor = color.background; } } // Paste captured placeholder rows onto the well // but from bottom up let r = height - 2; for (let i = placeholder.length - 1; i > 0; i--) { let row = placeholder[i]; for (let x = 0; x < width; x++) { if (row[x] != 0) { well[x][r] = 3; if (x != 0 && x != width - 1) { let square = document.getElementById("square_x"+x+"y"+r); if (square) square.style.backgroundColor = color.solid; } } } r--; } } } Tetris In The Dark (Included in source code!) Strategy video games have something called for of war. It covers an unexplored area of terrain with blackness. Adding Light To create a light spot, first I simply created a secondary grid sharing the same dimensions as the well and used it as an overlay. By default all DIV squares on that grid were set to black color and opacity of 1. Each square on secondary grid was assigned id of fog_x1y3 (if you wanted to access the square at x=1 and y=3 on the said grid of darkness.) Then I stored my light spot data in a separate array: // light position let light = { x: 0, y: 0 }; // lightspot data let light_mask = [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,4,4,0,0,0,0,0,0, 0,0,0,2,3,4,5,5,4,3,2,0,0,0, 0,0,2,3,4,5,6,6,5,4,3,2,0,0, 0,2,3,4,5,6,7,7,6,5,4,3,2,0, 0,3,4,5,6,7,8,8,7,6,5,4,3,0, 0,4,5,6,7,8,9,9,8,7,6,5,4,0, 0,4,5,6,7,8,9,9,8,7,6,5,4,0, 0,3,4,5,6,7,8,8,7,6,5,4,3,0, 0,2,3,4,5,6,7,7,6,5,4,3,2,0, 0,0,2,3,4,5,6,6,5,4,3,2,0,0, 0,0,0,2,3,4,5,5,4,3,2,0,0,0, 0,0,0,0,0,0,4,4,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0, ]; Here values between 0 to 9 represent 0.0 - 0.9 CSS opacity. I pasted this data into the dark grid using a simple for-loop (same way I pasted a tetromino into the well earlier,) this time using the draw_light() function: function draw_light() { let index = 0; for (let y = 0; y < 14; y++) { for (let x = 0; x < 14; x++, index++) { let posx = x + position.x; let posy = y + position.y; let id = "fog_x" + (posx - 6) + "y" + (posy - 6); let square = document.getElementById(id); if (square) { let type = light_mask[index]; if (type == 9) square.style.opacity = '0'; if (type == 8) square.style.opacity = '0.1'; if (type == 7) square.style.opacity = '0.2'; if (type == 6) square.style.opacity = '0.3'; if (type == 5) square.style.opacity = '0.4'; if (type == 4) square.style.opacity = '0.5'; if (type == 3) square.style.opacity = '0.7'; if (type == 2) square.style.opacity = '0.8'; if (type == 1) square.style.opacity = '0.9'; if (type == 0) square.style.opacity = '1.0'; } } } } This created the illusion of light fading into the darkness. Breaking Row Animation The row-breaking animation is done separately from everything else. It’s just a list of long horizontal DIV elements at every height level of the well. When a row needs to be broken, the clear_row() function (shown earlier) tracks the Y coordinate of each row that needs to be cleared. Then a setInterval function determines if state of that DIV is 1. If it is, it sets the DIV to white background color and plays an animation by reducing amount of opacity over time: Final Words When working with the same subject for a long period of time you tend to get a bit bored and an impulse to innovate awakens. Tetris In The Dark was born! As a game developer myself I decided to make an alternative version of Tetris by adding fog of war to it. Not all experiments turn out good. But when it comes to tetris in the dark, I’m quite pleased with the results.
http://damianfallon.blogspot.com/2020/04/how-i-built-my-own-tetris-game-from.html
0 notes